home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
qtawk
/
addcomma.exp
next >
Wrap
Text File
|
1990-01-07
|
591b
|
22 lines
# addcomma - put commas in numbers
# input : a number per line
# output : the number input followed by the number with commas and two decimal
# places
# AWK , page 72
{
printf("%-12s %20s\n",$0,addcomma($0));
}
# function to add commas to numbers
function addcomma(x) {
local num;
local spat;
local bnum = /{_d}{3,3}([,.]|$)/;
if ( x < 0 ) return "-" addcomma(-x);
num = sprintf("%.14g",x); # num is dddddd.dd
spat = num ~~ /\./ ? /{_d}{4,4}[.,]/ : /{_d}{4,4}(,|$)/;
while ( num ~~ spat ) sub(bnum,",&",num);
return num;
}